package com.jt.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService{

    @Autowired
    private UserMapper userMapper;

    @Override
    public List<User> findAll() {
        return userMapper.findAll();
    }

    @Override
    public User userById(Integer id) {
        return userMapper.userById(id);
    }

    public List<User> getUserByUS(User user){
        //根据对象不为null的属性充当where条件
        QueryWrapper queryWrapper = new QueryWrapper(user);
        return userMapper.selectList(queryWrapper);
    }

    @Override
    public List<User> getUserByName(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like("name", name);
        return userMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteByName(User user) {
        QueryWrapper queryWrapper = new QueryWrapper(user);
        userMapper.delete(queryWrapper);
    }

    @Override
    public void deleteUser(User user) {
        userMapper.delete(new QueryWrapper(user));
    }
    public void saveUser(User user){
        userMapper.insert(user);
    }

    @Override
    public List<User> selectName(String name) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("name", name);
        return userMapper.selectList(queryWrapper);
    }

    @Override
    public void deleteId(Integer id) {
        userMapper.deleteById(id);
    }

    @Override
    public void updateUser(User user) {
        //根据对象属性不为空 充当where条件id
        userMapper.updateById(user);
    }
}
